//
//  ByRecordListTitleCell.m
//  recordworktool_ios
//
//  Created by mc on 2017/12/6.
//  Copyright © 2017年 ZhangZhanbin. All rights reserved.
//

#import "ByRecordListTitleCell.h"

@interface ByRecordListTitleCell ()

@property (nonatomic, strong) UILabel *valueLabel;


@property (nonatomic, strong) UILabel *topLabel;
@property (nonatomic, strong) UILabel *centerLabel;
@property (nonatomic, strong) UILabel *bottomLabel;

@end

@implementation ByRecordListTitleCell

+ (instancetype)cellWithTableView:(UITableView*)tableView {
    
    static NSString *cellIdentifier = @"ByRecordListTitleCell";
    ByRecordListTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
    
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self =  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self createViews];
    }
    return self;
}


- (void)createViews{
    
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    UIView *view = [[UIView alloc] init];
    [self.contentView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(30);
        make.right.equalTo(self.contentView).offset(-30);
        make.top.equalTo(self.contentView).offset(20);
        make.bottom.equalTo(self.contentView).offset(-20);
    }];
    view.backgroundColor = rgba(247, 247, 247, 1);
    view.layer.cornerRadius = 10;
    CGFloat magin = 10;
    CGFloat width = (SCREEN_WIDTH - 30 * 2 - magin * 4) / 2;
    UILabel *valueLabel = [[UILabel alloc] init];
    [view addSubview:valueLabel];
    [valueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view).offset(magin);
        make.bottom.equalTo(view.mas_centerY).offset(0);
        make.size.mas_equalTo(CGSizeMake(width, 35));
    }];
    valueLabel.font = FONT(30);
    valueLabel.textColor = BY_THEME_COLOR;
    valueLabel.textAlignment = NSTextAlignmentCenter;
    valueLabel.text = @"1500.00";
    self.valueLabel = valueLabel;
    
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [view addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view.mas_centerY).offset(5);
        make.centerX.equalTo(valueLabel.mas_centerX).offset(0);
        make.size.mas_equalTo(CGSizeMake(width, 20));
    }];
    titleLabel.font = FONT(16);
    titleLabel.textColor = BY_THEME_COLOR;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"总余额";
    self.titleLabel = titleLabel;
    
    
    UILabel *topLabel = [[UILabel alloc] init];
    [view addSubview:topLabel];
    [topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view).offset(5);
        make.right.equalTo(view).offset(-magin);
        make.size.mas_equalTo(CGSizeMake(width, 20));
    }];
    topLabel.font = FONT(12);
    topLabel.textColor = TEXT_COLOR;
    topLabel.text = @"应收总和：6000.00";
    
    UILabel *centerLabel = [[UILabel alloc] init];
    [view addSubview:centerLabel];
    [centerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(view.mas_centerY).offset(0);
        make.right.equalTo(view).offset(-magin);
        make.size.mas_equalTo(CGSizeMake(width, 20));
    }];
    centerLabel.font = FONT(12);
    centerLabel.textColor = TEXT_COLOR;
    centerLabel.text = @"借支总额：1000.00";
    
    
    UILabel *bottomLabel = [[UILabel alloc] init];
    [view addSubview:bottomLabel];
    [bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(view).offset(-5);
        make.right.equalTo(view).offset(-magin);
        make.size.mas_equalTo(CGSizeMake(width, 20));
    }];
    bottomLabel.font = FONT(12);
    bottomLabel.textColor = TEXT_COLOR;
    bottomLabel.text = @"结算总额：0.00";
    
    self.topLabel = topLabel;
    self.centerLabel = centerLabel;
    self.bottomLabel = bottomLabel;
}


- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
   
    self.bottomLabel.text = [NSString stringWithFormat:@"结算金额：%.2f", _netModel.settlement.floatValue];
    self.centerLabel.text = [NSString stringWithFormat:@"借支金额：%.2f", _netModel.pre_borrow.floatValue];
    self.topLabel.text = [NSString stringWithFormat:@"应收总和：%.2f", _netModel.income.floatValue];
    self.valueLabel.text = [NSString stringWithFormat:@"%.2f", _netModel.debt.floatValue];
}



@end
